<?php
namespace Home\Controller;
class IndexController extends CommonController {
    public function _initialize(){
        parent::_initialize();
    }
    public function index(){
        $this->display();
    }

    /**
     * ajax搜索订单数据
     * @return mixed
     */
    public function search(){
        $result['status'] = 0;
        $result['data'] = [];
        $search_data = trim(I('get.search_data'));
        if(!$search_data){
            $result['msg'] = "请输入手机号码或者订单号";
            echo json_encode($result);die;
        }
        if(preg_match("/^1[34578]{1}\d{9}$/",$search_data)){
            $orderData = M('order')->where(['customer_phone'=>$search_data])->find();
        }else{
            $orderData = M('order')->where(['order_code'=>$search_data])->find();
        }
        if(!$orderData){
            $result['msg'] = "没有查询到对应的信息";
            echo json_encode($result);
            die;
        }
        $orderData['created_at'] = date('Y-m-d');
        $result['status'] = 1;
        $result['msg'] = 'success';
        $result['data'] = $orderData;
        echo json_encode($result);
    }

}